package com.mmsj;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class DialActivity extends AppCompatActivity {

    EditText editPhone;
    Button btnCall;
    Button btnContacts;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_dial);
//        初始化页面
//        获取组件
       editPhone = findViewById(R.id.edit_phone);
       btnCall = findViewById(R.id.btn_call);
       btnContacts = findViewById(R.id.btn_contacts);


//       给拨号按钮添加点击事件
        btnCall.setOnClickListener(v -> {
            String phone = editPhone.getText().toString();
            if (phone.isEmpty()){
                editPhone.setError("电话号码不能为空");
                return;
            }
//            创建意图
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+phone));
            // 启动意图
            startActivity(intent);
        });

        // 给联系人按钮添加点击事件
        btnContacts.setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/people"));
            startActivity(intent);
        });
    }
}